<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use app\model\not_del\UserModel as NotDelUserModel;

/**
 * 心理咨询-线下咨询
 */
class ConsultOfflineModel extends BaseModel
{
    protected $name = 'consult_offline';


    /**
     * 关联咨询用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class, 'uid')->bind([
            'user_name' => 'name',
            'user_avatar' => 'avatar',
            'department_id',
            'department_name'
        ]);
    }

    /**
     * 关联咨询师
     * @return BelongsTo
     */
    public function consult(): BelongsTo
    {
        return $this->belongsTo(NotDelUserModel::class, 'consult_id')->bind([
            'consult_name' => 'name',
            'consult_avatar' => 'avatar',
            'consult_online_num',
            'consult_offline_num',
            'consult_age' => 'age',
            'consult_sex' => 'sex',
        ]);
    }

    /**
     * 关联咨询问题类型
     * @return BelongsTo
     */
    public function questionName(): BelongsTo
    {
        return $this->belongsTo('ConsultQuestionModel', 'question_id')->bind([
            'question_name' => 'name',
        ]);
    }

    /**
     * 关联预约时间段
     * @return BelongsTo
     */
    public function ConsultTime(): BelongsTo
    {
        return $this->belongsTo('ConsultTimeModel', 'time_id')->bind([
            'reservation_start_time' => 'start_time',
            'reservation_end_time' => 'end_time'
        ]);
    }

    /**
     * 关联咨询任务
     * @return HasMany
     */
    public function task(): HasMany
    {
        return $this->hasMany('ConsultOfflineTaskModel', 'offline_id')->bind([
            'task_type' => 'type',
            'task_is_finish' => 'is_finish',
            'task_result_id' => 'result_id',
            'task_time' => 'time',
            'task_id' => 'id',
            'rating_scale_name',
            'rating_scale_cover',
            'is_follow'
        ]);
    }

}